#########################################
# Supplementary Information
#
# Toxic Speech and Limited Demand for Content
# Moderation on Social Media
#########################################

# R version 4.2.2 (2022-10-31)

# loading packages
library(dplyr) # dplyr version 2.3.2
library(tidyverse) #tidyverse version 2.0.0
library(ggplot2)  # ggplot2 3.4.2
library(sjPlot) # sjPlot verison 2.8.15
library(broom) # broom version 1.0.4
library(MetBrewer) # MetBrewer version 0.2.0
library(jtools) # jtools version 2.2.1
library(ggpubr) # ggpubr version 0.6.0
library(ggthemes) # ggthemes version 4.2.4
library(vtable) # vtable version 1.4.3
library(xtable) # xtable version 1.8-4
library(stargazer) # stargazer version 5.2.3

######################################
# A: Data and settings
######################################
#setting seed
set.seed(84104)

# setting ggplot themes, palettes
palettes <- ggthemes_data[["tableau"]][["color-palettes"]][["regular"]]

########################################################################################
# Study 1
########################################################################################
# Please set the working directory to the folder "code", and have one folder called "results" in the "replication files" folder, as well as a folder "appendix" inside the "results" folder

# LGBTQ
load("../data/lgbtq.RData")
iit_lgbtq <- iit2 
iit_lgbtq$study <- "Target: LGBTQ"
rm(iit2)

# Billionaires
load("../data/billionaires.RData")
iit_billionaires <- iit2 
iit_billionaires$study <- "Target: Billionaires"
rm(iit2)

# Highly-Religious 
load("../data/highly_religious.RData")
iit_religion <- iit2
iit_religion$study <- "Target: Highly Religious"
iit_religion <- iit2

rm(iit2)


# pooling all together: LGBTQ, Highly Religious, Billionaires
iit2_pooled <- dplyr::bind_rows(iit_lgbtq, iit_billionaires, iit_religion)

######################################
# B: Tables on sociodemographics
#    Tables S3 - Tables S6
######################################

# Tables S3, Sociodemographics LGBTQ study
description_sample_anes_lgbtq <- iit_lgbtq %>%
  select(c(gender,agegroup, racecat_anes, pid, educ)) 
st(description_sample_anes_lgbtq, out = "kable",digits = c(3)) %>% # if creating pdf, this needs to be commented out
  kable_classic()# prints in R 
st(description_sample_anes_lgbtq, out = "latex", digits = c(3),file = "../results/appendix/TableS3.tex") #saves a latex file

# Tables S4, Sociodemographics Billionaires study
description_sample_anes_billionaires <- iit_billionaires %>%
  select(c(gender,agegroup, racecat_anes, pid, educ)) 
st(description_sample_anes_billionaires, out = "kable",digits = c(3)) %>% # if creating pdf, this needs to be commented out
  kable_classic()# prints in R 
st(description_sample_anes_billionaires, out = "latex", digits = c(3), file = "../results/appendix/TableS4.tex") #saves a latex file

# Tables S5, Sociodemographics Christian study
description_sample_anes_religion <- iit_religion%>%
  select(c(gender,agegroup, racecat_anes, pid, educ)) 
st(description_sample_anes_religion, out = "kable",digits = c(3)) %>% # if creating pdf, this needs to be commented out
  kable_classic()# prints in R 
st(description_sample_anes_religion, out = "latex", digits = c(3),  file = "../results/appendix/TableS5.tex") #saves a latex file

# Tables S6, Sociodemographics Pooled Data
description_sample_anes_pooled <- iit2_pooled%>%
  select(c(gender,agegroup, racecat_anes, pid, educ)) 
st(description_sample_anes_pooled, out = "kable",digits = c(3)) %>% # if creating pdf, this needs to be commented out
  kable_classic()# prints in R 
st(description_sample_anes_pooled, out = "latex", digits = c(3), file = "../results/appendix/TableS6.tex") #saves a latex file

# ANES statistics source: https://electionstudies.org/resources/anes-guide/


###############################################
# C: Table Percent: Support "to do something"
#    Tables S7
###############################################
# function that produces percentages (support of any form of moderation)
percent_dosmth_function <- function(dataname, percentname){
  dataname <- dataname
  dataname$doSomething <- ifelse(dataname$handle != "Leave it, do nothing", 1, 0)
pct_doSomething <- aggregate(dataname$doSomething, list(dataname$treatment), FUN= mean) 
colnames(pct_doSomething) <- c("group", "percent")
pct_doSomething$group <- as.character(pct_doSomething$group) #needs to be changed to character, for next step
pct_doSomething <- rbind(c("all", mean(dataname$doSomething)), pct_doSomething) #adding overall percentage
pct_doSomething$percent <- as.numeric(pct_doSomething$percent)
pct_doSomething$percent <- round(pct_doSomething$percent, 2)*100 # rounding it
colnames(pct_doSomething) <- c("group", percentname) #rename percent
pct_doSomething
}

#LGBTQ percent "do something"
percent_dosmth_lgbtq <- percent_dosmth_function(dataname=iit_lgbtq, percentname="LGBTQ (%)")
#Billionaires percent "do something"
percent_dosmth_billionaires <- percent_dosmth_function(dataname=iit_billionaires, percentname="Billionaires (%)")
#Highly Religious percent "do something"
percent_dosmth_religion <- percent_dosmth_function(dataname=iit_religion, percentname="Highly Religious (%)")
#Pooled percent "do something"
percent_dosmth_pooled <- percent_dosmth_function(dataname=iit2_pooled, percentname="Pooled data (%)")

percent_dosmth_fulltable <- left_join(percent_dosmth_lgbtq, percent_dosmth_billionaires) %>%
  left_join(., percent_dosmth_religion) %>%
  left_join(., percent_dosmth_pooled)

#saving the table
library(xtable) # xtable version 1.8-4
print(xtable(percent_dosmth_fulltable, digits=c(0,0,0,0,0,0)), type="latex", file="../results/appendix/TableS7.tex", include.rownames = F)

##############################################################
# D: Preference for different types of moderation,
#    detailed information in one condensed Table
#    Table S8
#############################################################

# function that prodcues percentages (support for different types of moderation)
percentfunction <- function(data,namepercentcoulumn){
  library(dplyr) # dplyr version 1.1.1
pct_moderation <- data %>% 
  group_by(treatment) %>%
  count(handle) %>%
  mutate(percent = (n / sum(n) * 100), n=NULL) 
pct_moderation$percent <- round(pct_moderation$percent, 2) # round two digits
colnames(pct_moderation)[which(names(pct_moderation)=="percent")] <- namepercentcoulumn
pct_moderation  
}

pct_types_moderation_lgbtq <- percentfunction(data=iit_lgbtq, namepercentcoulumn="LGBTQ (%)")
pct_types_moderation_billioanires <- percentfunction(data=iit_billionaires, namepercentcoulumn="Billionaires (%)")
pct_types_moderation_religion <- percentfunction(data=iit_religion, namepercentcoulumn="Highly Religious (%)")
pct_types_moderation_pooled <- percentfunction(data=iit2_pooled, namepercentcoulumn="Pooled (%)")

pct_types_moderation_all <- left_join(pct_types_moderation_pooled, pct_types_moderation_lgbtq) %>%
  left_join(., pct_types_moderation_billioanires) %>% 
  left_join(., pct_types_moderation_religion)
pct_types_moderation_all

#double check if there are any missing values
table(iit2_pooled$handle, exclude=NULL) #double check if there are any missing values
table(iit_lgbtq$handle, exclude=NULL) 
table(iit_billionaires$handle, exclude=NULL)
table(iit_religion$handle, exclude=NULL) 

number_obervations <- data.frame("Obervations Pooled"=nrow(iit2_pooled), 
                                 "Obervations LGBTQ" =nrow(iit_lgbtq), 
                                 "Observations Billionaires"=nrow(iit_billionaires),
                                 "Observations Christians"=nrow(iit_religion))
number_obervations #manually included at the end of the table

# save Table in latex format
library(xtable) #xtable version 1.8-4
print(xtable(pct_types_moderation_all, digits = c(0,0,0,1,1,1,1)),include.rownames=FALSE,type = "latex", file="../results/appendix/TableS8.tex")

#############################################################################
# E: Logit models underlying the marginal effects displayed in Figure 2
#    Table S9
#############################################################################

# See 3_appendix_part2.R
allExp <- bind_rows(
  iit_lgbtq %>% 
    select(treatment,handle,uncivil,intolerant,threatening,pid) %>% 
    mutate(experiment = "LGBTQ"),
  iit_billionaires %>%
    select(treatment,handle,uncivil,intolerant,threatening,pid) %>%
    mutate(experiment = "Billionaires"),
  iit_religion %>%
    select(treatment,handle,uncivil,intolerant,threatening,pid) %>%
    mutate(experiment = "Christians")) %>%
  mutate(doSomething = ifelse(handle != "Leave it, do nothing", 1, 0),
         experiment = relevel(factor(experiment), ref="Christians"),
         pid = relevel(factor(pid), ref="Independent"),
         treatment = relevel(factor(treatment), ref="control")
  )

library(tidyverse) #  tidyverse version 2.0.0
library(broom) # broom version 1.0.4
library(marginaleffects) # marginaleffects version 0.7.0
library(modelsummary) # modelsummary version 1.4.2
allExp$doSomething <- as.factor(allExp$doSomething)
allExp$experiment
M_exp0  <- glm(doSomething ~ ., family="binomial", data= allExp %>%
                 select(doSomething,
                        `Type of post` =  treatment,  
                        `Respondent PID` = pid,
                        `Study` = experiment))
M_exp1  <- glm(doSomething ~ ., family="binomial", data= allExp %>% filter(experiment=="LGBTQ") %>%
                 select(doSomething,
                        `Type of post` =  treatment)) # `Respondent PID` = pid))
M_exp2  <- glm(doSomething ~ ., family="binomial", data= allExp %>% filter(experiment=="Billionaires") %>%
                 select(doSomething,
                        `Type of post` =  treatment)) #`Respondent PID` = pid))
M_exp3  <- glm(doSomething ~ ., family="binomial", data= allExp %>% filter(experiment=="Christians") %>%
                 select(doSomething,
                        `Type of post` =  treatment)) # `Respondent PID` = pid))


#Logit models underlying the marginal effects displayed in Figure 2
# Table S9
models <- list(
  "Pooled results"     = M_exp0,
  "LGBTQ target" = M_exp1,
  "Billionaire target"     = M_exp2,
  "Christian target" = M_exp3
)

library(xtable) # xtable version 1.8-4
write(modelsummary(models,
                   output = "latex"),file="../results/appendix/TableS9.tex")
#############################################################################
# F: Logistic regression underlying the contrasts displayed in Figure 4
#    Table S10
#############################################################################

tables10 <- glm(doSomething ~ factor(treatment) * factor(pid) * factor(experiment), family="binomial", 
    data=allExp %>% mutate(pid = factor(pid,levels = c("Independent","Republican","Democrat"))))
summary(tables10)

  ms <- modelsummary(tables10,shape = term ~ model + statistic,
               coef_rename = c("factor(treatment)non-group-related control" = "Anti-target (baseline)",
                               "factor(treatment)uncivil" = "Uncivil",
                               "factor(treatment)intolerant" = "Intolerant",
                               "factor(treatment)threatening" = "Threatening",
                               "factor(pid)Republican" = "Republican",
                               "factor(pid)Democrat" = "Democrat",
                               "factor(experiment)Billionaires" = "Billionaires",
                               "factor(experiment)LGBTQ" = "LGBTQ"),
               output = "latex")
  ms
  #saving output to a local file
library(xtable) # xtable version 1.8-4
  write(ms,file="../results/appendix/TableS10.tex")
  
#############################################################################
# G: Estimates and 95% confidence intervals displayed in Figure 4
#    Table S11
#############################################################################
  # Top panel of the Figure 4, and Table S11
  table(allExp$experiment, exclude=NULL)
  (fig4A <-
      glm(doSomething ~ factor(treatment) * factor(pid) * factor(experiment), family="binomial", 
          data=allExp %>% mutate(pid = factor(pid,levels = c("Republican","Democrat","Independent")))) %>%
      marginaleffects(., by =c("treatment","experiment"), variables = c("pid")) %>%
      tidy() %>%
      mutate(cont = case_when(contrast == "mean(Democrat) - mean(Republican)" ~ "Pr(Take action|Democrat) -\nPr(Take action|Republican)")) %>%
      filter(!is.na(cont)) %>%
      filter(treatment %in% c("control","uncivil","intolerant","threatening")) %>%
      mutate(
        treatment = case_when(
          treatment ==  "control" ~ "Anti-target\nbut without hostility",
          treatment ==  "uncivil" ~ "Uncivil post" ,
          treatment == "intolerant" ~ "Intolerant post",
          treatment == "threatening" ~ "Threatening post")
      ) %>%
      ggplot(aes(y=cont,x=estimate,
                 color=treatment,
                 shape=experiment,
                 xmin=conf.low,
                 xmax=conf.high)) +
      geom_pointrange(na.rm=TRUE, position=position_dodge(width=0.75), size=.5) +
      labs(x= "Partisan differences in demand for moderation
(higher values mean greater demand for moderation among Democrats)",
           caption = "",
           y="",
           color="Treatment",shape="Target") +
      theme_bw() +
      scale_color_tableau() +
      scale_x_continuous(labels = scales::percent) +
      geom_vline(xintercept = 0, linetype=2) +
      theme(text = element_text(size=15)) + facet_wrap(~treatment) )
  
  tableS11_topdf <- fig4A$data
  tableS11_top <- data.frame(`Treatment group`=tableS11_topdf$treatment, 
                             Target=tableS11_topdf$experiment,
                             Contrast = round(tableS11_topdf$estimate, 3),
                             `P.value`=tableS11_topdf$p.value,
                              CI=paste("[",round(tableS11_topdf$conf.low, 3),",",round(tableS11_topdf$conf.high,3),"]", sep=""))
  
  #saving the table
  library(xtable) #xtable version 1.8-4
  print(xtable(tableS11_top, digits=c(0,0,3,3,3,3)), type="latex", file="../results/appendix/TableS11_top.tex", include.rownames = F)
  
  # Bottom panel of the Figure 4, and Table S11
  (fig4B <-
      glm(doSomething ~ factor(treatment) * factor(pid) * factor(experiment), family="binomial", 
          data=allExp %>% mutate(pid = factor(pid,levels = c("Republican","Democrat","Independent")))) %>%
      marginaleffects(., by = c("pid","experiment"), variables = c("treatment")) %>%
      tidy() %>%
      filter(pid!="Independent") %>%
      mutate(var = case_when(
        contrast=="mean(intolerant) - mean(control)" ~ "Pr(Take action|intolerant) -\nPr(Take action|anti-target baseline)", 
        #contrast=="mean(non-group-related control) - mean(control)" ~ "Pr(Take action|movie) -\nPr(Take action|anti-target baseline)", 
        contrast=="mean(threatening) - mean(control)" ~ "Pr(Take action|threat) -\nPr(Take action|anti-target baseline)", 
        contrast=="mean(uncivil) - mean(control)" ~ "Pr(Take action|uncivil) -\nPr(Take action|anti-target baseline)"
      ),
      var2 = case_when(
        contrast=="mean(intolerant) - mean(control)" ~ "Effect of intolerant language", 
        contrast=="mean(threatening) - mean(control)" ~ "Effect of threatening language", 
        contrast=="mean(uncivil) - mean(control)" ~ "Effect of uncivil language"
      ), 
      ord = case_when(
        contrast=="mean(intolerant) - mean(control)" ~ 3, 
        contrast=="mean(non-group-related control) - mean(control)" ~ 1, 
        contrast=="mean(threatening) - mean(control)" ~ 4, 
        contrast=="mean(uncivil) - mean(control)" ~ 2
      )) %>%
      filter(!is.na(var)) %>%
      ggplot(aes(y=fct_reorder(var2,-ord),x=estimate,
                 color=pid,shape=experiment,
                 xmin=conf.low,
                 xmax=conf.high)) +
      geom_pointrange(na.rm=TRUE, position=position_dodge(width=0.45), size=.5) +
      labs(x= "Change in average probability of supporting content moderation\nrelative to an anti-target post without uncivil/tolerant/threatening language",
           y="",
           color="Respondent",shape="Target") +
      theme_bw() +
      scale_color_manual(values = c("red4","blue4")) +
      scale_x_continuous(labels = scales::percent) +
      geom_vline(xintercept = 0, linetype=2) +
      theme(text = element_text(size=15))
  )
  
  fig4B$data 
  tableS11_bottomdf <- fig4B$data
  
  #reordering the dataset
  #reorder data.frame
  tableS11_bottomdf$order[tableS11_bottomdf$var2=="Effect of intolerant language"] <- 1
  tableS11_bottomdf$order[tableS11_bottomdf$var2=="Effect of threatening language"] <- 2
  tableS11_bottomdf$order[tableS11_bottomdf$var2=="Effect of uncivil language"] <- 3
  tableS11_bottomdf$order2[tableS11_bottomdf$pid=="Republican"] <- 1
  tableS11_bottomdf$order2[tableS11_bottomdf$pid=="Democrat"] <- 2
  tableS11_bottomdf$order3[tableS11_bottomdf$experiment=="Christians"] <- 1
  tableS11_bottomdf$order3[tableS11_bottomdf$experiment=="Billionaires"] <- 2
  tableS11_bottomdf$order3[tableS11_bottomdf$experiment=="LGBTQ"] <- 3
  tableS11_bottomdf <- tableS11_bottomdf[order(tableS11_bottomdf$order,tableS11_bottomdf$order2,tableS11_bottomdf$order3), ]
  tableS11_bottomdf$order<- NULL
  tableS11_bottomdf$order2<- NULL
  tableS11_bottomdf$order3<- NULL
  tableS11_bottom <- data.frame(`Treatment group`=tableS11_bottomdf$var2, 
                             Target=tableS11_bottomdf$experiment,
                             `Respondents PID`=tableS11_bottomdf$pid,
                             Contrast = round(tableS11_bottomdf$estimate, 3),
                             CI=paste("[",round(tableS11_bottomdf$conf.low, 3),",",round(tableS11_bottomdf$conf.high,3),"]", sep=""))
  tableS11_bottom
  #saving the table
  library(xtable) #xtable version 1.8-4
  print(xtable(tableS11_bottom, digits=c(0,0,3,3,3,3)), type="latex", file="../results/appendix/TableS11_bottom.tex", include.rownames = F)
  
  # manually added Log Likelihood and AIC of the model (also the same as in Table S10)
  logLik(glm(doSomething ~ factor(treatment) * factor(pid) * factor(experiment), family="binomial", 
             data=allExp %>% mutate(pid = factor(pid,levels = c("Republican","Democrat","Independent")))))
  extractAIC(glm(doSomething ~ factor(treatment) * factor(pid) * factor(experiment), family="binomial", 
                 data=allExp %>% mutate(pid = factor(pid,levels = c("Republican","Democrat","Independent")))))
  
########################################################################################
# H: Age analyses - Analyzing social media use and moderation preferences by age
#    Figure S1-Figure S2
########################################################################################

# i) Table Age and Moderation Preferences
#kicking off older ones, because there are too few in our data set for this category
table(iit2_pooled$agegroup)
iit2_pooled$agegroup[which(iit2_pooled$agegroup=="Born 1927-1942")] <- NA
iit2_pooled$doSomething <- ifelse(iit2_pooled$handle != "Leave it, do nothing", 1, 0)
m1_age_moderation <- glm(doSomething ~ agegroup, data=iit2_pooled, family = "binomial")
summary(m1_age_moderation)

library(sjPlot) #sjPlot version 2.8.15
library(ggplot2) #ggplot2 version 3.4.2
#settings
textsize <- 33

p_moderation_link_age <- plot_model(m1_age_moderation, type = "pred", terms = c("agegroup"), color=I("black")) +
  coord_flip() +
  ylab("\nPredicted probability of supporting any form of moderation") + xlab("Age group") +
  theme_bw()  +
  scale_y_continuous(labels = scales::percent, limits = c(0,1)) +
  theme(text = element_text(size=textsize)) +
  ggtitle("\nModeration preferences by age group") 
p_moderation_link_age


png("../results/appendix/FigureS1.png", units="in", width=17, height=9, res=600)
p_moderation_link_age # insert ggplot code
dev.off()

# ii) Table Age and Social media Use
# creating a new variable of frequent media use vs. not frequent use
iit2_pooled$active_using <- NA
iit2_pooled$active_using[which(iit2_pooled$fil_lurker_visit=="Every day  " | iit2_pooled$fil_lurker_visit=="At least once a week but not every day  ")] <- 1
iit2_pooled$active_using[which(iit2_pooled$fil_lurker_visit=="A few times a month  " | iit2_pooled$fil_lurker_visit=="Less often")] <- 0
table(iit2_pooled$active_using, exclude=NULL)
# regression models social media use & age
m1_age_use <- glm(active_using ~ agegroup, data=iit2_pooled, family = "binomial")
summary(m1_age_use)
m1_age_use <- glm(active_using ~ agegroup, data=iit2_pooled, family = "binomial")
summary(m1_age_use)

p_use_link_age <- plot_model(m1_age_use, type = "pred", terms = c("agegroup"),color=I("black")) +
  coord_flip() +
  ylab("\nPrecited probability of frequent social media visits") + xlab("Age group") +
  theme_bw()  +
  scale_y_continuous(labels = scales::percent, limits = c(0,1)) +
  theme(text = element_text(size=textsize)) +
  ggtitle("\nFrequent social media visits by age group")
p_use_link_age

png("../results/appendix/FigureS2.png", units="in", width=17, height=9, res=600)
p_use_link_age # insert ggplot code
dev.off()
p_use_link_age



###############################################################################
########################################################################################
# I: Replicating the Effects of the LGBTQ study after Elon Musk's takeover
#    Figure S3, Figure S4, Table S12
########################################################################################
### loading data
# LGBTQ (Replication)
load("../data/lgbtq_replication.RData")
iit_lgbtq_rep <- iit2 
iit_lgbtq_rep$study <- "Target: LGBTQ (Replication)"
rm(iit2)

table(iit_lgbtq_rep$treatment)

# already loaded: Billionaires, Christian Study 
allExp_rep <- allExp <- bind_rows(
  iit_lgbtq_rep %>%  #here we load the replicated study
    select(treatment,handle,uncivil,intolerant,threatening,pid,rank_civil,rank_uncivil,rank_intolerant,rank_threatening,rank1) %>% 
    mutate(experiment = "LGBTQ"),
  iit_billionaires %>%
    select(treatment,handle,uncivil,intolerant,threatening,pid,rank_civil,rank_uncivil,rank_intolerant,rank_threatening,rank1) %>%
    mutate(experiment = "Billionaires"),
  iit_religion %>%
    select(treatment,handle,uncivil,intolerant,threatening,pid,rank_civil,rank_uncivil,rank_intolerant,rank_threatening,rank1) %>%
    mutate(experiment = "Christians")) %>%
  mutate(doSomething = ifelse(handle != "Leave it, do nothing", 1, 0),
         experiment = relevel(factor(experiment), ref="Christians"),
         pid = relevel(factor(pid), ref="Independent"),
         treatment = relevel(factor(treatment), ref="control")
  )

allExp_rep$treatment <- factor(allExp_rep$treatment, 
                              levels = c("non-group-related control", "control", "uncivil", "intolerant", "threatening", "threatening (new)"),
                              labels = c("No group mentioned", "Anti-target",  "Uncivil post",  "Intolerant post", "Threatening post", "Threatening post (new)"))


######################################################
# a) Figure S3, Replication LGBTQ effects Figure 2
######################################################

######################################################
# Replicated LGBTQ STUDY BY STUDY AME PLOTS
######################################################


M_exp1  <- glm(doSomething ~ ., family="binomial", data= allExp %>% filter(experiment=="LGBTQ") %>%
                 select(doSomething,
                        `Type of post` =  treatment)) 
summary(M_exp1)

(figure2_replicated <- marginaleffects::marginaleffects(M_exp1) %>% tidy() %>%
    arrange(term,estimate) %>%
    mutate(
      cont = case_when(
        contrast == "Republican - Independent"  ~ "Republican respondent",
        contrast == "Democrat - Independent" ~ "Democratic respondent",
        contrast == "non-group-related control - control" ~ "No group mentioned",
        contrast == "intolerant - control"~ "Intolerant post",
        contrast == "uncivil - control"  ~ "Uncivil post",
        contrast == "threatening - control"       ~ "Threatening post",
        contrast == "threatening (new) - control"       ~ "Threatening post (new)")
    ) %>%
    bind_rows(.,
              tribble(~ cont , ~ estimate, ~ term,
                      "Anti-target (baseline)",  0, "Treatment")
    ) %>%
    ggplot(aes(y=fct_reorder(cont,estimate),x=estimate,
               #color=factor(colterm),
               xmin=conf.low,
               xmax=conf.high)) +
    geom_pointrange(na.rm=TRUE, position=position_dodge(width=0.35), size=.15) +
    scale_x_continuous(labels = scales::percent, limits = c(-.5,.6)) +
    geom_vline(xintercept = 0, linetype=2) +
    scale_color_manual(values=c(`1`="black",`2`="darkgreen",`3`="blue",`4`="red")) +
    labs(
      subtitle = "Target: LGBTQ (Nov 2022)") +
    labs(x="Average Marginal Effect",y="",color="") +
    theme_bw() +
    theme(legend.position = "none",
          text = element_text(size=20))
)
figure2_replicated


#saving Figure 2  replication in the folder "results"
png("../results/appendix/FigureS3.png", units="in", width=17, height=9, res=600)
figure2_replicated # insert ggplot code
dev.off()


#################################################################################################
# b) Table S12, Regression tables of the main effects, next to the effects of the original study
#################################################################################################
# Replicated study regression results
table(iit_lgbtq_rep$treatment)
iit_lgbtq_rep$treatment <- factor(iit_lgbtq_rep$treatment, 
                                  levels = c("control", "non-group-related control", "uncivil", "intolerant", "threatening", "threatening (new)"),
                                  labels = c("Anti-target",   "No group mentioned", "Uncivil post",  "Intolerant post", "Threatening post", "Threatening post (new)")) 
table(iit_lgbtq_rep$treatment)

iit_lgbtq_rep$doSomething <- ifelse(iit_lgbtq_rep$handle != "Leave it, do nothing", 1, 0)
iit_lgbtq_rep$doSomething  <- as.factor(iit_lgbtq_rep$doSomething)
M_exp1  <- glm(doSomething ~ treatment, family="binomial", data= iit_lgbtq_rep) 
summary(M_exp1)

# Original LGBTQ study regression results
iit_lgbtq$treatment <- factor(iit_lgbtq$treatment, 
                                  levels = c("control", "non-group-related control", "uncivil", "intolerant", "threatening", "threatening (new)"),
                                  labels = c("Anti-target", "No group mentioned",  "Uncivil post",  "Intolerant post", "Threatening post", "Threatening post (new)")) 

iit_lgbtq$doSomething <- ifelse(iit_lgbtq$handle != "Leave it, do nothing", 1, 0)
M_exp1_org  <- glm(doSomething ~ treatment, family="binomial", data= iit_lgbtq) 
summary(M_exp1_org)
stargazer(M_exp1_org, M_exp1, ci=TRUE, type= "latex",
          star.char = c("*", "**", "***"),
          star.cutoffs = c(.05, .01, .001), out="../results/appendix/TableS12.tex")

####################################################
# c) Figure S4, Figure 3 with replicated LGBTQ study
#####################################################

# settings for creating the figure
legend_label <- "How should social media companies \nhandle the post?"
textsize <- 21

table(iit_lgbtq$treatment)
p_moderation_lgbtq <- iit_lgbtq %>% 
  group_by(treatment) %>%
  count(handle) %>%
  mutate(percent = n / sum(n) * 100) %>%
  ggplot(aes(y = fct_rev(treatment),
             x = percent,
             fill = handle)) +
  geom_col(width = .45, alpha=.9, colour="black") +
  labs(x = "Percent",
       y = "",
       title="",
       fill = legend_label) +
  theme_bw() +
  theme(text = element_text(size=textsize),
        legend.position = "right") +
  scale_fill_met_d(name = "Degas", direction = -1) +
  guides(fill=guide_legend(ncol=3,nrow=2,byrow=TRUE)) +
  scale_x_continuous(expand = c(0, 0))
p_moderation_lgbtq

table(iit_lgbtq_rep$treatment)
p_moderation_lgbtq_rep <- iit_lgbtq_rep %>% 
  group_by(treatment) %>%
  count(handle) %>%
  mutate(percent = n / sum(n) * 100) %>%
  ggplot(aes(y = fct_rev(treatment),
             x = percent,
             fill = handle)) +
  geom_col(width = .45, alpha=.9, colour="black") +
  labs(x = "Percent",
       y = "",
       title="",
       fill = legend_label) +
  theme_bw() +
  theme(text = element_text(size=textsize),
        legend.position = "right") +
  scale_fill_met_d(name = "Degas", direction = -1) +
  scale_x_continuous(expand = c(0, 0))
p_moderation_lgbtq_rep


library(dplyr) #dplyr version 1.1.1

figure3_rep <- ggarrange(
  p_moderation_lgbtq, NULL, p_moderation_lgbtq_rep, NULL, nrow=1, ncol=4, widths = c(1, 0.02, 1, 0.02),
  common.legend = TRUE, legend="bottom",
  labels = c("Target: LGBTQ (Jul 2022)", "", "Target: LGBTQ (Nov 2022)", "",  "Target: Billionaires (Jul 2022)", ""), 
  font.label = list(size = 24))  %>% annotate_figure(top= text_grob("Preferred actions in response to distinct post types\n", face = "bold", size = 28))
figure3_rep 

png("../results/appendix/FigureS4.png", units="in", width=22, height=14, res=600)
figure3_rep # insert ggplot code
dev.off()


#########################################################################
# d) Table S13, Replicated percentages of content moderation preferences
#########################################################################


# applying function that produces percentages, see function above, (support for different types of moderation)
pct_types_moderation_lgbtq <- percentfunction(data=iit_lgbtq, namepercentcoulumn="LGBTQ (%)")
pct_types_moderation_lgbtq_rep <- percentfunction(data=iit_lgbtq_rep, namepercentcoulumn="LGBTQ (Replication) (%)")


pct_types_moderation_lgbtqall <- left_join(pct_types_moderation_lgbtq, pct_types_moderation_lgbtq_rep) 
pct_types_moderation_lgbtqall

#double check if there are any missing values
table(iit_lgbtq_rep$handle, exclude=NULL) #double check if there are any missing values
table(iit_lgbtq$handle, exclude=NULL) 

number_obervations_lgbtq <- data.frame("Obervations LGBTQ" =nrow(iit_lgbtq), 
                                 "Obervations LGBTQ (Replication)"=nrow(iit_lgbtq_rep))
number_obervations_lgbtq #manually included at the end of the table

# save Table in latex format
library(xtable) #xtable version 1.8-4
print(xtable(pct_types_moderation_lgbtqall, digits = c(0,0,0,1,1)),include.rownames=FALSE,type = "latex", file="../results/appendix/TableS13.tex")

########################################################################################
# Study 2
########################################################################################
#########################################################
# A: Table S14: Overview treatment groups, see SI
#########################################################

#########################################################
# B: Table S15, Sociodemographics of study participants
#########################################################
# load partisans data
load("../data/partisans.RData")
iit_partisans <- iit2 
rm(iit2)

# Tables S15, Sociodemographics Pooled Data
description_sample_anes_pooled <- iit_partisans%>%
  select(c(gender,agegroup, racecat_anes, pid, educ)) 
st(description_sample_anes_pooled, out = "kable",digits = c(3)) %>% # if creating pdf, this needs to be commented out
  kable_classic()# prints in R 
st(description_sample_anes_pooled, out = "latex", digits = c(3),file = "../results/appendix/TableS15.tex") #saves a latex file

###############################################
# C: Logit models of Figure 5, Table S16
###############################################
set.seed(81477)
iit_partisans$randomMovieGroup <- sample(1:2,nrow(iit_partisans),replace = T)

pidstudy <- bind_rows(
  iit_partisans %>% filter(partisan=="target: democrats") %>%
    mutate(experiment = "Democrats"),
  iit_partisans %>% filter(treatment=="non-group-related control" & randomMovieGroup==1) %>%
    mutate(experiment = "Democrats"),
  iit_partisans %>% filter(partisan=="target: republicans") %>%
    mutate(experiment = "Republicans"),
  iit_partisans %>% filter(treatment=="non-group-related control" & randomMovieGroup==2) %>%
    mutate(experiment = "Republicans"),
)  %>%
  mutate(doSomething = ifelse(handle != "Leave it, do nothing", 1, 0),
         experiment = relevel(factor(experiment), ref="Republicans"),
         pid = relevel(factor(pid), ref="Independent"),
         treatment = relevel(factor(treatment), ref="control")
  ) %>%
  mutate(pid7 = 
           case_when(
             pid7 == "Democrat" ~ 1,
             pid7 == "Independent" ~ 2,
             pid7 == "Leaning Democrat" ~ 3,
             pid7 == "Leaning Republican" ~ 4,
             pid7 == "Republican" ~ 5,
             pid7 == "Strong Democrat" ~ 6,
             pid7 == "Strong Republican" ~ 7
           ))

model_logistic <- glm(doSomething ~ treatment + experiment + pid, family="binomial", data=pidstudy) 
summary(model_logistic)

library(stargazer) #stargazer version 5.2.3
stargazer(model_logistic, type= "latex",
          star.char = c("*", "**", "***"),
          star.cutoffs = c(.05, .01, .001), out="../results/appendix/TableS16.tex")


###############################################
# D: Logit models, contrasts of Figure 5, Table S17
###############################################

pidstudy$experiment <- factor(pidstudy$experiment,levels = c("Republicans","Democrats"))
pidstudy$treatment <- factor(pidstudy$treatment,levels = c("control","non-group-related control", "uncivil", "intolerant","threatening"))
m_figure5_b <- glm(doSomething ~ factor(treatment) * factor(pid) * factor(experiment), family="binomial", 
                   data=pidstudy %>% mutate(pid = factor(pid,levels = c("Independent","Republican","Democrat")))) 
summary(m_figure5_b)
# Model fit statistics Log Likelihood and AIC, see:
stargazer(m_figure5_b)

m_figure5_b_df <- data.frame(Coefficient = summary(m_figure5_b)$coefficients[,1],
                             Standard_Error = summary(m_figure5_b)$coefficients[,2])



library(stargazer) # stargazer version 5.2.3
stargazer(m_figure5_b_df, type= "latex",  summary=F,
          out="../results/appendix/TableS17.tex")

###############################################
# E: Table S18: Estimates and 95% confidence interval
#    top and bottom panel
###############################################
# a) top panel

mod_pidstudy <- glm(doSomething ~ treatment + experiment + pid, family="binomial", data=pidstudy) %>%
  marginaleffects::marginaleffects() %>% 
  tidy() 

AMEs <- mod_pidstudy %>% 
  mutate(term = recode(term,
                       experiment = "Target",
                       pid = "Affiliation (Party)",
                       treatment = "Treatment")) %>%
  mutate(
    cont = case_when(
      contrast == "Republican - Independent"  ~ "Republican respondent",
      contrast == "Democrat - Independent" ~ "Democratic respondent",
      contrast == "Democrats - Republicans" ~ "Target: A Democrat",
      contrast == "non-group-related control - control" ~ "No group mentioned",
      contrast == "intolerant - control"~ "Intolerant language",
      contrast == "uncivil - control"  ~ "Uncivil language",
      contrast == "threatening - control" ~ "Threatening language")
  ) %>%
  bind_rows(.,
            tribble(~ cont , ~ estimate, ~ term,
                    "Anti-target (baseline)",  0, "Treatment",
                    "Causal effects ↓",  NA, "Treatment",
                    "Target: A Republican (baseline)",  0, "Target",
                    "Observables ↓",  NA, "Affiliation (Party)")
  ) %>%
  arrange(term,estimate) %>% 
  mutate(
    ord = row_number(),
    colterm = c(4,3,3,rep(2,2),rep(1,6)))


(AMEplot <- AMEs %>%
    ggplot(aes(y=fct_reorder2(cont,term,-ord),x=estimate,
               color=factor(colterm),
               xmin=conf.low,
               xmax=conf.high)) +
    geom_pointrange(na.rm=TRUE, position=position_dodge(width=0.35), size=.70) +
    scale_x_continuous(labels = scales::percent) +
    geom_vline(xintercept = 0, linetype=2) +
    scale_color_manual(values=c(`1`="grey15",`2`="darkolivegreen4",`3`="blue3",`4`="brown2")) +
    labs(x="Average Marginal Effect",
         y="",
         color="") +
    theme_bw() +
    theme(legend.position = "none",
          text = element_text(size=18)) +
    theme(axis.ticks.y = element_blank()) +
    theme(axis.text.y = element_text(face = c(rep('plain',2), 'bold',rep('plain',7),'bold')))
)
m_figure5_top <- data.frame(Variable=AMEs$cont, Estimate = round(AMEs$estimate, 3),
                             CI=paste("[",round(AMEs$conf.low, 3),",",round(AMEs$conf.high,3),"]", sep=""), ord=AMEs$ord)
m_figure5_top <- m_figure5_top[order(-m_figure5_top$ord), ]
m_figure5_top
m_figure5_top$ord <- NULL
m_figure5_top

#saving the table
library(xtable) # xtable version 1.8-4
print(xtable(m_figure5_top, digits=c(0,3,3,3)), type="latex", file="../results/appendix/TableS18_top.tex", include.rownames = F)

# b) bottom panel
HETPID_B <-
  glm(doSomething ~ factor(treatment) * factor(pid) * factor(experiment), family="binomial", 
      data=pidstudy %>% mutate(pid = factor(pid,levels = c("Republican","Democrat","Independent")))) %>%
  marginaleffects(., by = c("pid","experiment"), variables = c("treatment")) %>%
  tidy() %>%
  filter(pid!="Independent") %>%
  mutate(var = case_when(
    contrast=="mean(intolerant) - mean(control)" ~ "Pr(Take action|intolerant) -\nPr(Take action|anti-target baseline)", 
    #contrast=="mean(non-group-related control) - mean(control)" ~ "Pr(Take action|movie) -\nPr(Take action|anti-target baseline)", 
    contrast=="mean(threatening) - mean(control)" ~ "Pr(Take action|threat) -\nPr(Take action|anti-target baseline)", 
    contrast=="mean(uncivil) - mean(control)" ~ "Pr(Take action|uncivil) -\nPr(Take action|anti-target baseline)"
  ),
  var2 = case_when(
    contrast=="mean(intolerant) - mean(control)" ~ "Effect of intolerant language", 
    contrast=="mean(threatening) - mean(control)" ~ "Effect of threatening language", 
    contrast=="mean(uncivil) - mean(control)" ~ "Effect of uncivil language"
  ), 
  ord = case_when(
    contrast=="mean(intolerant) - mean(control)" ~ 3, 
    contrast=="mean(non-group-related control) - mean(control)" ~ 1, 
    contrast=="mean(threatening) - mean(control)" ~ 4, 
    contrast=="mean(uncivil) - mean(control)" ~ 2
  ),
  target = case_when(
    experiment=="Democrats" ~ "A Democratic\ntarget",
    experiment=="Republicans" ~ "A Republican\ntarget"
  ),
  pid2 = case_when(
    pid=="Republican" ~ "Among Republicans",
    pid=="Democrat" ~"Among Democrats"
  ),
  lab = case_when(
    contrast=="mean(intolerant) - mean(control)" & experiment=="Democrats" ~ "A Democratic target",
    contrast=="mean(threatening) - mean(control)" & experiment=="Republicans" ~ "A Republican target"
  )) %>%
  filter(!is.na(var)) %>%
  group_by(pid) %>%
  mutate(mean_among_pid = mean(estimate)) %>%
  ungroup()
HETPID_B


m_figure5_bottom <- data.frame(`Treatment group`=HETPID_B$var2, Target = HETPID_B$experiment, 
                               `Respondents PID`=HETPID_B$pid, Estimate=HETPID_B$estimate, 
                               CI=paste("[",round(HETPID_B$conf.low, 3),",",round(HETPID_B$conf.high,3),"]", sep=""))

#reorder data.frame
m_figure5_bottom$order[m_figure5_bottom$Treatment.group=="Effect of intolerant language"] <- 1
m_figure5_bottom$order[m_figure5_bottom$Treatment.group=="Effect of threatening language"] <- 2
m_figure5_bottom$order[m_figure5_bottom$Treatment.group=="Effect of uncivil language"] <- 3
m_figure5_bottom$order2[m_figure5_bottom$Respondents.PID=="Republican"] <- 1
m_figure5_bottom$order2[m_figure5_bottom$Respondents.PID=="Democrat"] <- 2
m_figure5_bottom$order3[m_figure5_bottom$Target=="Republicans"] <- 1
m_figure5_bottom$order3[m_figure5_bottom$Target=="Democrats"] <- 2
m_figure5_bottom <- m_figure5_bottom[order(m_figure5_bottom$order,m_figure5_bottom$order2,m_figure5_bottom$order3), ]
m_figure5_bottom$order<- NULL
m_figure5_bottom$order2<- NULL
m_figure5_bottom$order3<- NULL
m_figure5_bottom

#saving the table
library(xtable) #xtable version 1.8-4
print(xtable(m_figure5_bottom, digits=c(0,0,0,3,3,3)), type="latex", file="../results/appendix/TableS18_bottom.tex", include.rownames = F)

# Model fit statistics Log Likelihood and AIC, manually added (see also Table S17, same statistics)
extractAIC(glm(doSomething ~ treatment + experiment + pid, family="binomial", data=pidstudy))
logLik(glm(doSomething ~ treatment + experiment + pid, family="binomial", data=pidstudy))

###############################################
# E: Percent: Support "to do something"
#    Partisan study - Tables S19
###############################################
iit2_democrats <- subset(iit_partisans, partisan=="target: democrats" | partisan=="non-group-related control")
iit2_republicans <- subset(iit_partisans, partisan=="target: republicans" | partisan=="non-group-related control")

#Democrats percent "do something"
percent_dosmth_democrats<- percent_dosmth_function(dataname=iit2_democrats, percentname="Democrats (Target) (%)")
#Republicans percent "do something"
percent_dosmth_republicans <- percent_dosmth_function(dataname=iit2_republicans, percentname="Republicans (Target) (%)")
#Pooled percent "do something"
percent_dosmth_partisans <- percent_dosmth_function(dataname=iit_partisans, percentname="Partisans (Pooled) (%)")

percent_dosmth_fulltable_study2 <- left_join(percent_dosmth_democrats, percent_dosmth_republicans) %>%
  left_join(., percent_dosmth_partisans) 

# function that produces percentages (support of any form of moderation)
percent_dosmth_function <- function(dataname, percentname){
  dataname <- dataname
  dataname$doSomething <- ifelse(dataname$handle != "Leave it, do nothing", 1, 0)
  pct_doSomething <- aggregate(dataname$doSomething, list(dataname$treatment), FUN= mean) 
  colnames(pct_doSomething) <- c("group", "percent")
  pct_doSomething$group <- as.character(pct_doSomething$group) #needs to be changed to character, for next step
  pct_doSomething <- rbind(c("all", mean(dataname$doSomething)), pct_doSomething) #adding overall percentage
  pct_doSomething$percent <- as.numeric(pct_doSomething$percent)
  pct_doSomething$percent <- round(pct_doSomething$percent, 2)*100 # rounding it
  colnames(pct_doSomething) <- c("group", percentname) #rename percent
  pct_doSomething
}

iit2_republicans$do_something <- ifelse(iit2_republicans$handle != "Leave it, do nothing", 1, 0)
#saving the table
library(xtable) # xtable version 1.8-4
print(xtable(percent_dosmth_fulltable_study2, digits=c(0,0,0,0,0)), type="latex", file="../results/appendix/TableS19.tex", include.rownames = F)



##############################################################
# F: Preference for different types of moderation,
#    detailed information in one condensed Table
#    Table S20 - Partisan study
#############################################################

pct_types_moderation_partisans <- percentfunction(data=iit_partisans, namepercentcoulumn="Partisans (Pooled) (%)")
pct_types_moderation_democrats <- percentfunction(data=iit2_democrats, namepercentcoulumn="Democrats (Target) (%)")
pct_types_moderation_republicans <- percentfunction(data=iit2_republicans, namepercentcoulumn="Republicans (Target) (%)")

pct_types_moderation_all_partisans <- left_join(pct_types_moderation_partisans, pct_types_moderation_democrats) %>%
  left_join(., pct_types_moderation_republicans) 
pct_types_moderation_all_partisans

#double check if there are any missing values
table(iit_partisans$handle, exclude=NULL) #double check if there are any missing values
table(iit2_democrats$handle, exclude=NULL) 
table(iit2_republicans$handle, exclude=NULL)

number_obervations_partisans <- data.frame("Obervations Partisans (Pooled)"=nrow(iit_partisans), 
                                 "Obervations Democrats (Target)" =nrow(iit2_democrats), 
                                 "Observations Republicans (Target)"=nrow(iit2_republicans))
number_obervations_partisans #manually included at the end of the table

# save Table in latex format
library(xtable) # xtable version 1.8-4
print(xtable(pct_types_moderation_all_partisans, digits = c(0,0,0,1,1,1)),include.rownames=FALSE,type = "latex", file="../results/appendix/TableS20.tex")

##############################################################
# G: Participants’ preferences for removing vs. 
# keeping a post in response to distinct post
# types measured with a slider question [0,100]
# Table S1 - SI on Recruitment Procedure and Experimental Process
#############################################################

#################### adding table M1-M5 Remove vs keep
# for LGBTQ study, the labels have already renamed in an earlier step 
iit_lgbtq$treatment <- factor(iit_lgbtq$treatment, 
                                     levels = c("No group mentioned", "Anti-target",  "Uncivil post",  "Intolerant post", "Threatening post"))

iit_billionaires$treatment <- factor(iit_billionaires$treatment, 
                                     levels = c("non-group-related control", "control", "uncivil", "intolerant", "threatening"),
                                     labels = c( "No group mentioned", "Anti-target",  "Uncivil post",  "Intolerant post", "Threatening post")) 
iit_religion$treatment <- factor(iit_religion$treatment, 
                                 levels = c("non-group-related control", "control", "uncivil", "intolerant", "threatening"),
                                 labels = c( "No group mentioned", "Anti-target",  "Uncivil post",  "Intolerant post", "Threatening post")) 
iit2_democrats$treatment <- factor(iit2_democrats$treatment, 
                                   levels = c("non-group-related control", "control", "uncivil", "intolerant", "threatening"),
                                   labels = c( "No group mentioned", "Anti-target",  "Uncivil post",  "Intolerant post", "Threatening post")) 

iit2_republicans$treatment <- factor(iit2_republicans$treatment, 
                                     levels = c("non-group-related control", "control", "uncivil", "intolerant", "threatening"),
                                     labels = c( "No group mentioned", "Anti-target",  "Uncivil post",  "Intolerant post", "Threatening post")) 
# a) LGBTQ

#remove
m1_lgbtq <- lm(remove ~ treatment, data = iit_lgbtq)
summary(m1_lgbtq)
# b) Billionaires
#remove
m2_bill <- lm(remove ~ treatment, data = iit_billionaires)
summary(m2_bill)
# c) Christians
m3_rel <- lm(remove ~ treatment, data = iit_religion)
summary(m3_rel)
# d) Democrats
m4_dem <- lm(remove ~ treatment, data = iit2_democrats)
# e) Republicans
m5_rep <- lm(remove ~ treatment, data = iit2_republicans)


library(stargazer) # stargazer version 5.2.3
stargazer(m1_lgbtq, m2_bill, m3_rel, m4_dem, m5_rep,
          type= "latex",
          star.char = c("*", "**", "***"),
          star.cutoffs = c(.05, .01, .001), out="../results/appendix/TableS1_prereg_procedure.tex", title="Participants' preferences for removing vs. keeping a post in response to distinct post types measured with a slider question [0,100]")



##############################################################
# H: -Further analysis -
# Multiple linear regression on participants’ emotions anger 
# and disgust measured with slider questions [0,100]
# Table S21
#############################################################
iit_partisans$treatment <-factor(iit_partisans$treatment,levels=c("non-group-related control",
                                 "control","uncivil","intolerant","threatening"),
                                 labels = c("No group mentioned", "Anti-target",  "Uncivil post",  "Intolerant post", "Threatening post")) 
# pooled data
pooled_all <- bind_rows(
  iit_lgbtq %>% 
    select(treatment,handle,uncivil,intolerant,threatening,pid,anger,disgust,fil_lurker_visit) %>% 
    mutate(experiment = "LGBTQ"),
  iit_billionaires %>%
    select(treatment,handle,uncivil,intolerant,threatening,pid,anger,disgust,fil_lurker_visit) %>%
    mutate(experiment = "Billionaires"),
  iit_religion %>%
    select(treatment,handle,uncivil,intolerant,threatening,pid,anger,disgust,fil_lurker_visit) %>%
    mutate(experiment = "Highly Religious"),
  iit_partisans %>%
    select(treatment,handle,uncivil,intolerant,threatening,pid,anger,disgust,fil_lurker_visit) %>%
    mutate(experiment = "Partisans")) %>%
  mutate(doSomething = ifelse(handle != "Leave it, do nothing", 1, 0),
         experiment = relevel(factor(experiment), ref="Highly Religious"),
         pid = relevel(factor(pid), ref="Independent"),
         treatment = relevel(factor(treatment), ref="No group mentioned"))
table(pooled_all$treatment, exclude=NULL)

pooled_all$fil_lurker_visit <-trimws(pooled_all$fil_lurker_visit) #getting rid of whitespace in the string


# Anger
mc_anger_pooled <- lm(anger~treatment, data=pooled_all) 
summary(mc_anger_pooled)

# Disgust
mc_disgust_pooled <- lm(disgust~treatment, data=pooled_all) 
summary(mc_disgust_pooled)


stargazer(mc_anger_pooled,mc_disgust_pooled, type= "latex",
          star.char = c("*", "**", "***"), ci = TRUE,
          star.cutoffs = c(.05, .01, .001), out="../results/appendix/TableS21.tex")

##############################################################
# I: -Further analysis -
# Binomial logistic regression on support 
# for any form of content moderation
# Table S22
#############################################################

table(pooled_all$fil_lurker_visit)
pooled_all$fil_lurker_visit_dummy <- ifelse(pooled_all$fil_lurker_visit == "Every day"|pooled_all$fil_lurker_visit == "At least once a week but not every day", 
                                            "Frequent social media user", "Infrequent social media user") 
pooled_all$fil_lurker_visit_dummy <-factor(pooled_all$fil_lurker_visit_dummy,
                                           levels = c("Infrequent social media user", "Frequent social media user"))
table(pooled_all$fil_lurker_visit_dummy) #checks
hte_sm <- glm(doSomething~treatment*fil_lurker_visit_dummy, data=pooled_all,family = "binomial")
summary(hte_sm)

stargazer(hte_sm, type= "latex",
          star.char = c("*", "**", "***"),
          star.cutoffs = c(.05, .01, .001), out="../results/appendix/TableS22.tex")




